package com.unlcn.ils.kas.scheduled;

import java.util.List;

import com.unlcn.ils.kas.dao.model.order.OrderOtd;
import com.unlcn.ils.kas.service.constant.CronConstant;
import com.unlcn.ils.kas.service.order.SharesOrderService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class RefreshJMCPlanShip2TimeScheduled {
  private final static Logger logger = LoggerFactory.getLogger(RefreshJMCPlanShip2TimeScheduled.class);
  @Autowired
  SharesOrderService service;

  @Scheduled(cron = CronConstant.REFRESH_JMC_PLAN_SHIP_TO_TIME_JOB)
  public void reCalculateJMCPlanShip2TimeScheduled() {
    List<OrderOtd> otdLst = service.getNeedRefreshOrders();
    for (OrderOtd orderOtd : otdLst) {
      try {
        service.updateNewestPositionRelInfo(orderOtd.getSysOrderNo());
      } catch (Exception e) {
        logger.error("RefreshJMCPlanShip2TimeScheduled.reCalculateJMCPlanShip2TimeScheduled: ", e);
      }
    }
  }
}
